package com.salesmanager.core.modules.cms.impl;

import com.aliyun.oss.OSSClient;
import com.salesmanager.core.business.content.model.OutputContentFile;
import com.salesmanager.core.business.generic.exception.ServiceException;
import com.salesmanager.core.constants.Constants;
import com.salesmanager.core.modules.cms.aliyun.OSSClientFactory;
import com.salesmanager.core.modules.cms.common.CmsFileManager;
import com.salesmanager.core.utils.AliyunOssUtil;
import com.salesmanager.core.utils.CoreConfiguration;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.InputStream;

/**
 * Created by Liutong on 10/15/15.
 */
@Service("cmsFileManager")
public class CmsFileManagerImpl implements CmsFileManager {

    @Resource
    private OSSClientFactory ossClientFactory;

    @Resource
    private CoreConfiguration configuration;



    @Override
    public void put(String path, String fileName, InputStream in) throws ServiceException {
        OSSClient ossClient = ossClientFactory.getInstance();
        AliyunOssUtil.createObject(ossClient,
                configuration.getProperty(Constants.ALIYUN_BUCKET_NAME),
                path,in);
    }

    @Override
    public OutputContentFile get(String path, String FileName) throws ServiceException {
        return null;
    }

    @Override
    public void remove(String path, String FileName) throws ServiceException {
        OSSClient ossClient = ossClientFactory.getInstance();
        AliyunOssUtil.removeObjcet(ossClient,
                configuration.getProperty(Constants.ALIYUN_BUCKET_NAME),
                path
                );
    }
}
